package com.rmkj.trade.match.core;

/**
 * Created by Administrator on 2019/1/8.
 */
public final class Goods {
	private String name;
	private String symbol;
	private int precision;

	/**
	 * 09:30-12:30,13:30-16:00
	 *
	 * null为24小时无休
	 */
	private TradingPeriods tradingPeriods;

	public Goods(String symbol) {
		this(null, symbol, 1, null);
	}

	public Goods(String symbol, int precision) {
		this(null, symbol, precision, null);
	}

	public Goods(String name, String symbol, int precision) {
		this(name, symbol, precision, null);
	}

	public Goods(String name, String symbol, int precision, TradingPeriods tradingPeriods) {
		this.name = name;
		this.symbol = symbol;
		this.precision = Math.min(Math.max(precision, 0), 10);
		this.tradingPeriods = tradingPeriods;
	}

	public String getName() {
		return name;
	}

	public String getSymbol() {
		return symbol;
	}

	public int getPrecision() {
		return precision;
	}

	public TradingPeriods getTradingPeriods() {
		return tradingPeriods;
	}

	public String parse(double price){
		return String.format("%.0"+this.getPrecision()+"f", price);
	}

	@Override
	public String toString() {
		return "Goods{" +
				"name='" + name + '\'' +
				", symbol='" + symbol + '\'' +
				", precision=" + precision +
				", tradingPeriods='" + tradingPeriods + '\'' +
				'}';
	}

}
